package com.king.wms.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.king.wms.mapper.LocMapper;
import com.king.wms.pojo.Loc;
import com.king.wms.pojo.Sku;

@Service
@Transactional
public class LocService {
	@Autowired
	private LocMapper locMapper;

	public String update(Loc loc) {
		Integer remain  = loc.getStackremianed();
		Integer used = loc.getStackuesd();
		Integer limit = loc.getStacklimit();
		if( limit < used ){
			return "该  "+loc.getLoc_id()+" 库位，已经存放了  "+used+" 个单元的物品，请设置大于 "+used+" 个空间单元限制";
		}else{
			remain = limit - used;
			loc.setStackremianed(remain);
			locMapper.update(loc);
			return "success";
		}
		
	}

	public void delete(Integer loc_id) {
		locMapper.deleteByPrimaryKey(loc_id);
	}

	public void insert(Loc loc) {
		locMapper.insert(loc);
	}

	public List<Loc> findAll() {
		return locMapper.findAll();
	}

	public Loc findLocByLoc(Integer loc_id) {
		return locMapper.selectByPrimaryKey(loc_id);
	}

	public List<Sku> findSkuByloc_id(Integer loc_id) {
		// TODO Auto-generated method stub
		return locMapper.findSkuByloc_id(loc_id);
	}

}
